# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Sébastien Luttringer

pkgname=arpwatch
pkgver=3.3
pkgrel=3
pkgdesc='Ethernet/FDDI station activity monitor'
arch=('loong64' 'x86_64')
url='https://ee.lbl.gov/'
license=('BSD')
depends=('libpcap' 'smtp-forwarder')
source=("https://ee.lbl.gov/downloads/arpwatch/arpwatch-$pkgver.tar.gz"
        'LICENSE'
        "ethercodes.dat.gz"
        "$pkgname.service")
sha512sums=('4e3d542917dc9060ae7b35b40f41cb696eb36e68846194a76f025c5ecb1df1e67d5c1c66ba3c7e581e1f915b988d05cb7805f28d410784bd27dc3a448dccdece'
            'ed46c36220507d8ffbd01a3cc90c9047536b8af26af8c9623fae7a6584ad922b6adebabb6de771b0dbdc802da1a6cb51b8b30a8902c92d71f8b31ee763d61624'
            'dc9818e6453e0d9ef38864536ea66b15a8acb48091b609e422227538d3d4c6b93cc853778f8f4ea8cd887dc15c1c62da66f4325c540eb80f9c78705d63a65226'
            '4a9460c8a376d9183265b73e2c3b02965223144fecfeeb630ec5e70d40d4aed5725e5a43ae370938afa0a2fd362785020eca679e585a7f400e4e67f255807a84')

prepare() {
  cd $pkgname-$pkgver
  sed -i '/@HAVE_FREEBSD_TRUE@/d' Makefile.in
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --mandir=/usr/share/man \
    --sbindir=/usr/bin \
    --with-watcher=arpwatch
  make SENDMAIL=/usr/bin/sendmail
}

package() {
  cd $pkgname-$pkgver
  install -d -m 0755 "$pkgdir"/usr/{bin,share/man/man8}
  make DESTDIR="$pkgdir" install
  # install ether prefix database
  install -Dm644 "$srcdir"/ethercodes.dat "$pkgdir/var/lib/$pkgname/ethercodes.dat"
  # license
  install -Dm644 "$srcdir"/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  # systemd
  install -Dm644 "$srcdir"/$pkgname.service "$pkgdir/usr/lib/systemd/system/$pkgname@.service"
}
